﻿; (function (window, undefined, $) {
    $(document).ready(function () {
        var gridopt = {
            url: options.listUrl,
            colModel: [
                    { display: '项目编号', name: 'ProjectNo', width: "10%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: 'pid', name: 'pid', hide: true, sortable: false, align: 'left' },
                    { display: '项目名称', name: 'ProjectName', width: "10%", sortable: false, align: 'left' },
                    { display: '借款总额', name: 'TotalLoan', width: "10%", sortable: false, align: 'left' },
                    { display: '还款编号', name: 'RepaymentPlanNO', width: "10%", sortable: false, align: 'left' },
                    { display: '还款日期', name: 'RepaymentPlanDate', width: "10%", sortable: false, align: 'left' },
                    { display: '当期本息', name: 'CurrentPrincipal', width: "10%", sortable: false, align: 'left' },
                    { display: '剩余本金', name: 'RemainingPrincipal', width: "10%", sortable: false, align: 'left' },
                    { display: '还款状态', name: 'statusName', width: "10%", sortable: false, align: 'left', hide: true },
                    { display: '操作', name: 'ID', width: "10%", sortable: false, align: 'center', process: processOp }
            ],
            sortname: "ID",
            sortorder: "ASC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[8]=="已还款") {
                ops.push("&nbsp;&nbsp;已还款");
            } else {
                ops.push("&nbsp;&nbsp;<a title='还款明细' class='abtn' href='javascript:;'  onclick=\"util.RepayDetail('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>还款明细</a>");
            }
            return ops.join("");
        }

        util.RepayPres = function (id,pid) {
            $.post(options.Repayment, { id: id, projectid: pid, name: $('#RepaymentUser').val() },
                  function (res) {
                      if (res > 0) {
                          if (res == 10001) {
                              alert('还没到还款时间！');
                          }
                          else if (res == 10003) {
                              alert('已还款！');
                          }
                          else {
                              window.location.href = "/Project/RepaymentList.html";
                          }
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };

        util.RepayDetail = function (id, pid) {
            var url = "RepaymentDetail?id=" + id + "&pid=" + pid;
            location.href = url;
        };
    });

})(window, undefined, jQuery);